package verb.Activity;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class adaptadorImagen extends BaseAdapter{
private Context mContext;
	
	// Keep all Images in array
	public Integer[] opciones = {
			R.drawable.opcion_1, R.drawable.opcion_2, R.drawable.opcion_3, 
			R.drawable.opcion_4, R.drawable.opcion_5, R.drawable.opcion_6,
			R.drawable.opcion_7, R.drawable.opcion_8, R.drawable.opcion_9
	};
	
	// Constructor
	public adaptadorImagen(Context c){
		mContext = c;
	}

	@Override
	public int getCount() {
		return opciones.length;
	}

	@Override
	public Object getItem(int position) {
		return opciones[position];
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
//	public View getView(int position, View convertView, ViewGroup parent) {			
//		ImageView imageView = new ImageView(mContext);
//        imageView.setImageResource(opciones[position]);
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
////        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
////        imageView.setLayoutParams(new GridView.LayoutParams(params));
//        return imageView;
//	}
//    public View getView(int position, View convertView, ViewGroup parent) {
//        ImageView imageView;
//        if (convertView == null) {  // if it's not recycled, initialize some attributes
//            imageView = new ImageView(mContext);
//            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
//            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//            imageView.setPadding(0, 0, 0, 0);
//        } else {
//            imageView = (ImageView) convertView;
//        }
//        imageView.setImageResource(opciones[position]);
//        return imageView;
//    }

    public View getView(int position, View convertView, ViewGroup parent) {

		ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(opciones[position]);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(new GridView.LayoutParams(GetDipsFromPixel(85), GetDipsFromPixel(85)));
        return imageView;
    }

    public int GetDipsFromPixel(float pixels) {
     // Get the screen's density scale
     final float scale = mContext.getResources().getDisplayMetrics().density;
     // Convert the dps to pixels, based on density scale
     return (int) (pixels * scale + 0.5f);
    }

}
